var docSide=angular.module('docSide',[]);
docSide.directive('docSideBar',function(){
    return {
        restrict : 'EA',
        transclude : true,
        scope : {
            conf : '='
        },
        templateUrl:'page/directive/docSide.html',
        link : function(scope, element, attrs) {
            if(attrs.menu=='noProduct'){
                scope.showProduct=false;
                scope.index=2;
            }else{
                scope.showProduct=true;
                scope.index=3;
            }
            scope.docTitle=attrs.doctitle;
            var  hideMenu;
                if(attrs.hideMenu){
                hideMenu=attrs.hideMenu.split(",");
            }

            for(var i=0 in hideMenu){
                var str= hideMenu[i];
                $("#"+str).parent().hide();
            }
            var screenWidth = parseInt($(window).width());
            element.find('.drop-down').on('click', function(){
                $(this).next().slideToggle();
                $(this).hasClass('up') ? $(this).removeClass('up') : $(this).addClass('up');
            });
            element.find('.menu-item>ol>li>a').on('click', function(){
                $(".menu-item>ol>li>a").removeClass('active');
                $(this).addClass('active')
                $(".doc-main-container>.doc-common-content").hide();
                $(".doc-main-container>." + $(this).attr('id')).show();
                if(screenWidth < 770){
                    $(".doc_top_menu").next().hide();
                }else{
                    $('html, body').animate({         //添加animate动画效果
                        scrollTop: 280 + "px"
                    }, 100);
                };
            });
            $(".skip_link").click(function(e){
                var className=$(e.target).attr("class");
                var classArr=className.split(" ");
                var classTar ;
                for(var i=0 in classArr){
                   if(classArr[i].indexOf("jump")>=0){
                       classTar=classArr[i].substr(5);
                       break;
                   }
                }
                $(".menu-item>ol>li>a").removeClass('active');
                $("#"+classTar).addClass('active')
                $(".doc-main-container>.doc-common-content").hide();
                $(".doc-main-container>."+classTar).show();
                $(".menu-item>ol").hide();
                $("#"+classTar).parent().parent().show();
                $('html, body').animate({         //添加animate动画效果
                    scrollTop: 0
                }, 100);
            })

            angular.element(document).ready(function () {
                var headerHeight = $('.navbar_box_wrap').outerHeight();
                // 侧边栏固定
                var footerHeight = $('.footer').outerHeight();
                var $sidebar = $('.doc-sidebar-wrapper');
                var screenHeight=$(window).height();
                $(window).on('load scroll resize', function () {
                    var offsetTop = window.scrollY || window.pageYOffset;
                    // sidebar fixed 时跟底部保持的距离
                    var offsetBottom = document.body.scrollHeight - offsetTop - window.innerHeight;
                    var bottom = 0;
                    if (offsetBottom < footerHeight) {
                        bottom = footerHeight - offsetBottom;
                    }

                    var wrapperHeight;


                    if(screenWidth<765){
                        $sidebar.css({
                            position: 'absolute'
                        })
                        $(".doc-sidebar").css({
                            paddingTop:"0px" ,
                            height:"auto"
                        })

                    }else{
                        wrapperHeight= $('.doc-sidebar-wrapper').height() || 0;
                        $sidebar.find('.doc-sidebar').css({
                            'height':wrapperHeight
                        });
                        if (offsetTop > headerHeight) {
                            $sidebar.css({
                                position: 'fixed'
                            })
                            $(".doc-sidebar").css({
                                paddingTop:"10px"
                            })
                            $sidebar.find('.doc-sidebar').css({
                                'height':(screenHeight-bottom)
                            });

                        } else {

                            $sidebar.css({
                                position: 'absolute'
                            })
                            $(".doc-sidebar").css({
                                paddingTop:"75px"
                            })
                        }
                    }



                });
            });

        }
    }
});
var sendEmail =  angular.module('sendEmail',[]);
sendEmail.directive('ngSendEmail', function ($http, $rootScope,$timeout) {
    return{
        restrict:'A',
        link: function (scope, element, attrs , ctrl) {
            scope.btnText="发送信息";
            scope.btnDisabled=false;
            element.on('click', function(){
               if(scope.sendForm.$invalid) return false;
                scope.btnText="发送中...";
                scope.btnDisabled=true;
                scope.user.inbox="ipaynow@ipaynow.cn"
                $http({
                    method  : 'POST',
                    url     : $rootScope.basePath + 'mailAction/sendMail.do',
                    data    : $.param(scope.user),
                    dataType: 'json',
                    headers : {
                        'Content-Type': 'application/x-www-form-urlencoded'
                    }
                }).success(function(data) {
                        if (data.respCode == 'success') {
                            scope.btnText="发送成功";
                            scope.btnDisabled=false;
                            var timer = $timeout(
                                function() {
                                    scope.btnText="发送信息";
                                },
                                3000
                            );
                        }else{
                            scope.btnText="发送失败";
                            scope.btnDisabled=false;
                        }
                });
            });

        }
    }
});
sendEmail.directive('ngBtnHover', function ($http, $rootScope) {
    return{
        restrict:'A',
        link: function (scope, element, attrs , ctrl) {
           element.on('mouseenter', function(){
                $(this).parent('.fifth-contet-btn').addClass('fifth-contet-btn-h');
           }).on('mouseleave', function(){
                $(this).parent('.fifth-contet-btn').removeClass('fifth-contet-btn-h');
           });
        }
    }
});